/*
 * @Description: 自定义步骤条
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-28 09:36:39
 * @LastEditors: ZhengZhuang
 * @LastEditTime: 2019-08-28 10:03:41
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LeftLineWidget extends StatelessWidget {
  final bool showTop;
  final bool showBottom;
  final bool isLight;
  final Color colour;

  const LeftLineWidget(this.showTop, this.showBottom, this.isLight, this.colour);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16),
      width: 16,
      child: CustomPaint(
        painter: LeftLinePainter(showTop, showBottom, isLight, colour),
      ),
    );
  }
}

class LeftLinePainter extends CustomPainter {
  static const double _topHeight = 16;
  static const Color _lightColor = Colors.deepPurpleAccent;
  // static const Color _normalColor = colour;

  final bool showTop;
  final bool showBottom;
  final bool isLight;
  final Color colour;

  const LeftLinePainter(this.showTop, this.showBottom, this.isLight, this.colour);

  @override
  void paint(Canvas canvas, Size size) {
    double lineWidth = ScreenUtil().setWidth(2.0);
    double centerX = size.width / 2;
    Paint linePain = Paint();
    linePain.color = showTop ? Color.fromARGB(255, 215, 215, 215) : Colors.transparent;
    linePain.strokeWidth = lineWidth;
    linePain.strokeCap = StrokeCap.square;
    canvas.drawLine(Offset(centerX, 0), Offset(centerX, _topHeight), linePain);
    Paint circlePaint = Paint();
    // circlePaint.color = isLight ? _lightColor : _normalColor;
    circlePaint.color = colour;
    circlePaint.style = PaintingStyle.fill;
    linePain.color = showBottom ? Color.fromARGB(255, 215, 215, 215) : Colors.transparent;
    canvas.drawLine(
        Offset(centerX, _topHeight), Offset(centerX, size.height), linePain);
    canvas.drawCircle(Offset(centerX, _topHeight), centerX, circlePaint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}